package com.ruoyi.spicfz.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.spicfz.domain.Executives;
import com.ruoyi.spicfz.service.IExecutivesService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 高管信息Controller
 * 
 * @author ruoyi
 * @date 2021-09-02
 */
@Controller
@RequestMapping("/spicfz/executives")
public class ExecutivesController extends BaseController
{
    private String prefix = "spicfz/executives";

    @Autowired
    private IExecutivesService executivesService;

    @RequiresPermissions("spicfz:executives:view")
    @GetMapping()
    public String executives()
    {
        return prefix + "/executives";
    }

    /**
     * 查询高管信息列表
     */
    @RequiresPermissions("spicfz:executives:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Executives executives)
    {
        startPage();
        List<Executives> list = executivesService.selectExecutivesList(executives);
        return getDataTable(list);
    }

    /**
     * 导出高管信息列表
     */
    @RequiresPermissions("spicfz:executives:export")
    @Log(title = "高管信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Executives executives)
    {
        List<Executives> list = executivesService.selectExecutivesList(executives);
        ExcelUtil<Executives> util = new ExcelUtil<Executives>(Executives.class);
        return util.exportExcel(list, "高管信息数据");
    }

    /**
     * 新增高管信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存高管信息
     */
    @RequiresPermissions("spicfz:executives:add")
    @Log(title = "高管信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Executives executives)
    {
        return toAjax(executivesService.insertExecutives(executives));
    }

    /**
     * 修改高管信息
     */
    @GetMapping("/edit/{executiveId}")
    public String edit(@PathVariable("executiveId") Long executiveId, ModelMap mmap)
    {
        Executives executives = executivesService.selectExecutivesById(executiveId);
        mmap.put("executives", executives);
        return prefix + "/edit";
    }

    /**
     * 修改保存高管信息
     */
    @RequiresPermissions("spicfz:executives:edit")
    @Log(title = "高管信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Executives executives)
    {
        return toAjax(executivesService.updateExecutives(executives));
    }

    /**
     * 删除高管信息
     */
    @RequiresPermissions("spicfz:executives:remove")
    @Log(title = "高管信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(executivesService.deleteExecutivesByIds(ids));
    }

    /**
     * 查看高管信息
     */
    @GetMapping("/detail/{executiveId}")
    public String detail(@PathVariable("executiveId") Long executiveId, ModelMap mmap)
    {
        Executives executives = executivesService.selectExecutivesById(executiveId);
        mmap.put("executives", executives);
        mmap.put("detail","true");
        return prefix + "/edit";
    }

}
